package com.hanhanxiaochong.zhongxiangchuanmei.view.my.adapter;

import android.content.Context;

import com.hanhanxiaochong.zhongxiangchuanmei.R;
import com.hanhanxiaochong.zhongxiangchuanmei.bean.WorkAttendanceBean;
import com.hanhanxiaochong.zhongxiangchuanmei.config.CommonAdapter;
import com.hanhanxiaochong.zhongxiangchuanmei.config.ViewHolder;

import java.util.List;

/**
 * Created by RockPhoenix on 2018/6/10.
 */

public class ClockListAdapter extends CommonAdapter<WorkAttendanceBean.LestBean> {

    public ClockListAdapter(Context context, int layoutId, List<WorkAttendanceBean.LestBean> datas) {
        super(context, layoutId, datas);
    }

    @Override
    protected void convert(ViewHolder holder, WorkAttendanceBean.LestBean bean, int position) {
        String[] date = bean.getDay().split("-");
        holder.setText(R.id.tv_year, date[0]);
        holder.setText(R.id.tv_month_day, date[1] + "-" + date[2]);
        List<WorkAttendanceBean.LestBean.ListBean> list = bean.getList();
        if (list.size() >= 2) {
            for (WorkAttendanceBean.LestBean.ListBean listBean : list) {
                if (listBean.getType().equals("1")) {
                    holder.setText(R.id.tv_go_to_work_time, listBean.getTime());
                } else {
                    holder.setText(R.id.tv_go_off_work_time, listBean.getTime());
                }
            }
        } else if (list.size() == 1) {
            if (list.get(0).getType().equals("1")) {
                holder.setText(R.id.tv_go_to_work_time, list.get(0).getTime());
                holder.setText(R.id.tv_go_off_work_time, "未打卡");
            } else {
                holder.setText(R.id.tv_go_to_work_time, "未打卡");
                holder.setText(R.id.tv_go_off_work_time, list.get(0).getTime());
            }
        } else {
            holder.setText(R.id.tv_go_to_work_time, "未打卡");
            holder.setText(R.id.tv_go_off_work_time, "未打卡");
        }
    }
}
